﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using CoreEx.Database.Linq.Translators;
using CoreEx.Database.Query.Expressions;
using LinFu.IoC.Configuration;

namespace CoreEx.Database.Linq.Implementation.Translators
{
    [Implements(typeof(IExpressionTranslator_generic<UnaryExpression>))]
    public class UnaryExpressionTranslatorGeneric : ExpressionTranslatorGenericBase<UnaryExpression>
    {
        public UnaryExpressionTranslatorGeneric(TranslateResult translateResult) : base(translateResult) {}

        public override DbExpression Translate(UnaryExpression expression)
        {
            if (expression.Type == typeof(bool) && expression.NodeType == ExpressionType.Not)
                return ExpressionFactory.Not(Visit(expression.Operand));

            return Visit(expression.Operand);
        }
    }
}
